import React, { useState } from 'react';
import { FlatList, RefreshControl } from 'react-native';
const renderFlatList = (props: any) => {
	const [refreshing, setRefreshing] = useState(false);

	const {
		data, // 数组 array
		renderItem, // 渲染页面函数
		// onEndReachedThreshold = 0.9, // 决定当距离内容最底部还有多远时触发onEndReached回调
	} = props;

	const _onRefresh = () => {
		if (refreshing === false) {
			_updateState(true);

			//5秒后结束刷新
			setTimeout(() => {
				_updateState(false);
			}, 5000);
		}
	};

	//更新State
	const _updateState = (refresh: boolean) => {
		setRefreshing(refresh);
	};

	return (
		<FlatList
			style={{ width: gScreen.screenWidth }}
			data={data}
			renderItem={renderItem}
			refreshControl={
				<RefreshControl
					tintColor={'red'}
					titleColor={'brown'}
					title={'正在刷新......'}
					refreshing={refreshing}
					onRefresh={_onRefresh}
				/>
			}
			keyExtractor={(item: any) => item.sid}
			// onEndReached={onEndReached}
			// onRefresh={() => console.log(111)}
		/>
	);
};
const styles = {};
export default renderFlatList;
